package org.jg.arkanoid.controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import org.jg.arkanoid.gameobjects.Carriage;
import org.jg.arkanoid.util.Vector;

public class CarriageKeyListener  implements KeyListener{

	private final Carriage carriage;

	public CarriageKeyListener(Carriage carriage)
	{
		this.carriage = carriage;
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		int preddesKey = e.getKeyCode();
		if(preddesKey == KeyEvent.VK_RIGHT)
		{
			carriage.setVelocity(new Vector(carriage.getHorizontalVelocity(), 0));
		}
		if(preddesKey == KeyEvent.VK_LEFT)
		{
			carriage.setVelocity(new Vector(-carriage.getHorizontalVelocity(), 0));
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		carriage.setVelocity(new Vector(0, 0));
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
	}

}
